﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLyPhongKham
{
    public partial class ProcessDialog : Form
    {
        private ProcessController _control;
        public ProcessDialog()
        {
            InitializeComponent();
            
        }

        public ProcessDialog(ProcessController control)
        {
            InitializeComponent();
            this._control = control;
            
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this._control.GetStatus()) {
                try
                {
                    this.timer1.Enabled = false;
                    this.timer1.Stop();
                }
                catch (Exception ex)
                {
                    //write log here
                }
                finally {
                    this.Dispose();
                }
            }
        }

        private void ProcessDialog_Load(object sender, EventArgs e)
        {
            if (this._control == null)
                throw new Exception("The ProcessController object must not be null");
            this.timer1.Enabled = true;
            Point position = this._control.GetPosition();
            Size size = this._control.GetWidthHeight();
            if (position != Point.Empty && size != Size.Empty)
            {
                this.Left = this._control.GetPosition().X + this._control.GetWidthHeight().Width / 2 - this.Width / 2;
                this.Top = this._control.GetPosition().Y + this._control.GetWidthHeight().Height / 2 - this.Height / 2;
            }
        }
    }
}
